package com.chenyaowei.web.controller.product.relation;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.chenyaowei.common.annotation.Log;
import com.chenyaowei.common.core.controller.BaseController;
import com.chenyaowei.common.core.domain.AjaxResult;
import com.chenyaowei.common.enums.BusinessType;
import com.chenyaowei.product.domain.CywBrandCategoryRelation;
import com.chenyaowei.product.service.ICywBrandCategoryRelationService;
import com.chenyaowei.common.utils.poi.ExcelUtil;
import com.chenyaowei.common.core.page.TableDataInfo;

/**
 * 品牌分类关联Controller
 *
 * @author 陈耀威
 * @date 2023-11-23
 */
@Api("品牌分类关联")
@RestController
@RequestMapping("/product/brandCategoryRelation")
public class CywBrandCategoryRelationController extends BaseController
{
    @Autowired
    private ICywBrandCategoryRelationService cywBrandCategoryRelationService;

    @GetMapping("/brand/{catelogId}")
    public AjaxResult selectBrandListByCatelogId(@PathVariable("catelogId") Long catelogId){
        List<CywBrandCategoryRelation> list = cywBrandCategoryRelationService.selectBrandListByCatelogId(catelogId);
        return success(list);
    }

    /**
     * 新增品牌分类关联
     */
    @PreAuthorize("@ss.hasPermi('product:brandCategoryRelation:add')")
    @Log(title = "品牌分类关联", businessType = BusinessType.INSERT)
    @PostMapping("/{brandId}/{catelogId}")
    public AjaxResult saveCywBrandCategoryRelation(
            @PathVariable("brandId") Long brandId,
            @PathVariable("catelogId") Long catelogId)
    {
        return toAjax(cywBrandCategoryRelationService.saveCywBrandCategoryRelation(brandId, catelogId));
    }

    /**
     * 查询品牌分类关联列表
     */
    @PreAuthorize("@ss.hasPermi('product:brandCategoryRelation:list')")
    @GetMapping("/list")
    public TableDataInfo list(CywBrandCategoryRelation cywBrandCategoryRelation)
    {
        startPage();
        List<CywBrandCategoryRelation> list = cywBrandCategoryRelationService.selectCywBrandCategoryRelationList(cywBrandCategoryRelation);
        return getDataTable(list);
    }

    /**
     * 导出品牌分类关联列表
     */
    @PreAuthorize("@ss.hasPermi('product:brandCategoryRelation:export')")
    @Log(title = "品牌分类关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CywBrandCategoryRelation cywBrandCategoryRelation)
    {
        List<CywBrandCategoryRelation> list = cywBrandCategoryRelationService.selectCywBrandCategoryRelationList(cywBrandCategoryRelation);
        ExcelUtil<CywBrandCategoryRelation> util = new ExcelUtil<CywBrandCategoryRelation>(CywBrandCategoryRelation.class);
        util.exportExcel(response, list, "品牌分类关联数据");
    }

    /**
     * 获取品牌分类关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:brandCategoryRelation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cywBrandCategoryRelationService.selectCywBrandCategoryRelationById(id));
    }

    /**
     * 修改品牌分类关联
     */
    @PreAuthorize("@ss.hasPermi('product:brandCategoryRelation:edit')")
    @Log(title = "品牌分类关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CywBrandCategoryRelation cywBrandCategoryRelation)
    {
        return toAjax(cywBrandCategoryRelationService.updateCywBrandCategoryRelation(cywBrandCategoryRelation));
    }

    /**
     * 删除品牌分类关联
     */
    @PreAuthorize("@ss.hasPermi('product:brandCategoryRelation:remove')")
    @Log(title = "品牌分类关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cywBrandCategoryRelationService.deleteCywBrandCategoryRelationByIds(ids));
    }
}
